﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace SBPweb.RIA.Client.Controls.Converters
{

    public class FormatConverter<T> : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter != null)
            {
                string formatString = parameter.ToString();

                if (!string.IsNullOrEmpty(formatString))
                {
                    return string.Format(culture, formatString, value);
                }
            }

            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                return DateTime.Parse(value.ToString());
            }
            return value;
        }

    }

}